package com.simple.hystrixtest.controller;

import com.simple.hystrix.annotation.DoHystrix;
import com.simple.hystrixtest.entity.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述:
 *
 * @author: WuChengXing
 * @create: 2021-12-27 16:25
 **/
@RestController
public class HystrixController {

    private Logger logger = LoggerFactory.getLogger(HystrixController.class);

    /**
     * 测试：http://localhost:8081/api/queryUserInfo?userId=aaa
     */
    @DoHystrix(timeoutValue = 350, returnJson = "{\"code\":\"1111\",\"info\":\"调用方法超过350毫秒，熔断返回！\"}")
    @GetMapping("/api/queryUserInfo")
    public UserInfo queryUserInfo(@RequestParam String userId) throws InterruptedException {
        logger.info("查sq询用户信息，userId：{}", userId);
        Thread.sleep(1000);
        return new UserInfo("simple:" + userId, 19, "杭州市文新街道-0000");
    }

}
